package statisticalCalculator;

public class BinomialDistribution {
	private double numOfEvents;
	private double numOfSuccess;
	private double probability;

	public BinomialDistribution(double _numOfEvents, double _numOfSuccess,
			double _probability) {
		if ((_numOfEvents <= 0) || (_numOfSuccess <= 0)
				|| (_numOfSuccess > _numOfEvents)
				|| (_probability > 1 || _probability < 0))
			throw new IllegalArgumentException("Invalid Arguments");

		numOfEvents = _numOfEvents;
		numOfSuccess = _numOfSuccess;
		probability = _probability;
	}

	public double getNumberOfEvents() {

		return numOfEvents;
	}

	public double getNumberOfSuccess() {
		return numOfSuccess;
	}

	public double getProbabilty() {
		return probability;
	}

	public int calculateFactorial(int n) {
		int result = 1;
		for (int i = 1; i <= n; i++) {
			result *= i;
		}
		return result;
	}

	public int calculateCombination(int n, int k) {
		int numerator = calculateFactorial(n);
		int denomenator = calculateFactorial(n - k) * calculateFactorial(k);
		return numerator / denomenator;

	}

	public double calculateBinomialDistribution() {
		double result = calculateCombination((int) numOfEvents,
				(int) numOfSuccess)
				* Math.pow(probability, numOfSuccess)
				* Math.pow(1 - probability, numOfEvents - numOfSuccess);
		return result;
	}

}
